<template>
  <!-- 清算账户余额警戒值设置页面弹出框-->
  <el-dialog
    title="清算账户余额警戒值设置"
    center
    :visible.sync="open"
    width="1024px"
    :close-on-click-modal="false"
    @close="closeFn"
  >
    <el-form ref="settingsForm" :model="formData" :rules="rules" label-width="135px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="被设置清算行行号：" prop="bankCode">
            <el-input v-model="formData.bankCode" placeholder="被设置清算行行号" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="被设置清算行行名：" prop="stbrname">
            <el-input v-model="formData.stbrname" placeholder="被设置清算行行名" disabled />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="当前预警开关类型：" prop="clrSwitchType">
            <el-select v-model="formData.clrSwitchType" placeholder="请选择" style="width: 100%" disabled>
              <el-option
                v-for="dict in dictMap.SWITCHTYPECODE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="货币币种：" prop="clrCurrency">
            <el-input v-model="formData.clrCurrency" placeholder="货币币种" disabled />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="当前预警金额：" prop="clrWarnValue">
            <el-input v-model="formData.clrWarnValue" placeholder="当前预警金额" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="当前预警正负标志：" prop="clrWarnPmFlag">
            <el-select v-model="formData.clrWarnPmFlag" placeholder="请选择" style="width: 100%" disabled>
              <el-option
                v-for="dict in dictMap.PLUSMINUSTYPECODE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="最后设置成功时间：" prop="clrTime">
            <el-date-picker
              disabled
              v-model="formData.clrTime"
              type="date"
              value-format="yyyyMMdd"
              placeholder="选择时间"
              style="width: 100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12"></el-col>
      </el-row>
      <el-divider></el-divider>
      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="预警开启关闭类型：" prop="switchType">
            <el-select v-model="formData.switchType" placeholder="请选择" style="width: 100%" @change="switchChange">
              <el-option
                v-for="dict in dictMap.SWITCHTYPECODE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="货币币种：" prop="curcd">
            <el-input v-model="formData.curcd" placeholder="货币币种" disabled />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex" v-if="isControl">
        <el-col :span="12">
          <el-form-item label="预警金额：" prop="warnValue">
            <HtAmountInput v-model="formData.warnValue" placeholder="预警金额" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="预警正负标志：" prop="warnPmFlag">
            <el-select v-model="formData.warnPmFlag" placeholder="请选择" style="width: 100%">
              <el-option
                v-for="dict in dictMap.PLUSMINUSTYPECODE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="备注：" prop="remarks">
            <el-input type="textarea" v-model="formData.remarks" placeholder="备注" maxlength="256" show-word-limit />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm" :loading="isLoading">提交</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { save } from "@/api/cnaps/nets/AcctLimtWarn/setting_clearing_entry.js";
import HtAmountInput from "@/views/components/HtAmountInput/index.vue";
import { log } from "util";
export default {
  name: "warningSetting",
  components: {HtAmountInput},
  props: {
    dictMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
    formData: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      isControl: true,
      // 是否显示弹出层
      open: false,
      isLoading: false,
      rules: {
        switchType: [
          {
            required: true,
            message: "必填",
            trigger: "change",
          },
        ],
        warnValue: [
          {
            required: true,
            message: "必填",
            trigger: "blur",
          },
        ],
        warnPmFlag: [
          {
            required: true,
            message: "必填",
            trigger: "change",
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    // 表单重置
    reset() {
      this.resetForm("settingsForm");
      // this.$set(this, "form", {});
    },
    closeFn() {
      this.open = false;
    },
    show() {
      this.open = true;
    },
    // 预警开启关闭类型切换方法
    switchChange(val) {
      if (val === "ST00") {
        this.$set(this, "isControl", true);
      } else {
        this.$set(this, "isControl", false);
      }
    },
    submitForm() {
      this.$refs["settingsForm"].validate((valid) => {
        if (valid) {
          this.isLoading = true;
          save(this.formData)
            .then((res) => {
              this.msgSuccess("提交成功！");
              this.isLoading = false;
              this.open = false;
              this.$emit("editComplete", true);
            })
            .catch((err) => {
              this.isLoading = false;
            });
        }
      });
    },
    cancel() {
      this.open = false;
      this.reset();
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
